package com.zidian.study.adapter;

import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.zidian.student.trucks.R;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by GongCheng on 2016/12/1.
 */

public class TopListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private List<String> tags;
    private static final String[] COLORS = {"#fb6834", "#e6933d", "#86bb4e", "#666666"};
    private static final int IMAGES[] =
            {R.drawable.top1, R.drawable.top2, R.drawable.top3, R.drawable.top4,
                    R.drawable.top5, R.drawable.top6, R.drawable.top7,
                    R.drawable.top8, R.drawable.top9, R.drawable.top10};

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_top_tag, parent, false);
        return new TagTopViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof TagTopViewHolder) {
            switch (position) {
                case 0:
                    ((TagTopViewHolder) holder).topListTagTv.setTextColor(Color.parseColor(COLORS[0]));
                    break;
                case 1:
                    ((TagTopViewHolder) holder).topListTagTv.setTextColor(Color.parseColor(COLORS[1]));
                    break;
                case 2:
                    ((TagTopViewHolder) holder).topListTagTv.setTextColor(Color.parseColor(COLORS[2]));
                    break;
                default:
                    ((TagTopViewHolder) holder).topListTagTv.setTextColor(Color.parseColor(COLORS[3]));
                    break;
            }
            ((TagTopViewHolder) holder).topListImageIv.setImageResource(IMAGES[position]);
            ((TagTopViewHolder) holder).topListTagTv.setText(tags.get(position));

        }
    }

    @Override
    public int getItemCount() {
        return tags == null ? 0 : tags.size();
    }

    public void setTags(List<String> tags) {
        this.tags = tags;
        notifyDataSetChanged();
    }

    static class TagTopViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.top_list_image_iv)
        ImageView topListImageIv;
        @Bind(R.id.top_list_tag_tv)
        TextView topListTagTv;

        public TagTopViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
